package com.neusoft.demo9;

import java.util.*;

public class CollectionDemo {
    public static void main(String[] args) {
        //创建一个List集合
        List<Map<String, Person>> list = new ArrayList<>();
        //创建三个Map容器
        Map<String, Person> map1 = new HashMap<>();
        Person p1 = new Person();
        p1.setName("tom");
        Person p2 = new Person();
        p2.setName("fender");
        //将对象保存到Map集合
        map1.put("p1", p1);
        map1.put("p2", p2);
        Map<String, Person> map2 = new HashMap<>();
        Person p3 = new Person();
        p3.setName("gibson");
        Person p4 = new Person();
        p4.setName("yamaha");
        map2.put("p3", p3);
        map2.put("p4", p4);
        //将map1和map2添加到List中
        list.add(map1);
        list.add(map2);
        //遍历输出
        //遍历list {
            //每循环一次获取到一个Map集合
            //对当前map集合遍历输出对象信息
        //}
        Iterator<Map<String,Person>> it = list.iterator(); //遍历list
        while (it.hasNext()) {
            Map<String,Person> map = it.next();
            //遍历Map集合
            Set<Map.Entry<String,Person>> set = map.entrySet();
            Iterator<Map.Entry<String,Person>> its = set.iterator();
            while (its.hasNext()) {
                Map.Entry<String,Person> m = its.next(); //获取到map集合中的一个元素
                //获取到key值
                String key = m.getKey();
                //获取到value值
                Person p = m.getValue();
                System.out.println(key + "---" + p.getName());
            }
        }
    }
}
